package com.idp.ebay.test;

import java.util.ArrayList;
import java.util.List;

import com.ebay.sdk.ApiException;
import com.ebay.sdk.SdkException;
import com.ebay.soap.eBLBaseComponents.OrderType;
import com.ebay.soap.eBLBaseComponents.SiteCodeType;
import com.ebay.soap.eBLBaseComponents.TransactionType;
import com.idp.ebay.domain.EBayInfo;
import com.idp.ebay.utils.ExcelFileUtil;

public class TongBu {
	@SuppressWarnings("deprecation")
	public static void main(String[] args) throws ApiException, SdkException, Exception {
		// TODO Auto-generated method stub
		GetOrders Get = new GetOrders();
		Get.setToken(
				"AgAAAA**AQAAAA**aAAAAA**tDs6WQ**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6AAkoOnDpOCpgidj6x9nY+seQ**9cUDAA**AAMAAA**PuQorHNQufQ2LZjs7smj4Q+CMkDrkGg1zZxvKG5x8x97hnYn3X7LswF1MBiDgSOwEj58dRs5+1UEI64ndj6qLaGWhy6WoMK+PXpaKR3cvCizyls7KibrnogVIs1YxdpqejKJcpY9wCbV+5hvKJSTd5AW1HmM5G6L5h8YGAmaHcXhlYpTSZsZ9P6dl8qKfuFJ24pI0mNPM7sSDg46B39y0Ph3HQJylMMN8m7teYyyShxyvd9EXUdyUBkkcLQgo9qpGyS4T0DGNiCCw2RWjM2yTp7VHgsDZP3UHpaP8/vge2Xe5zEx0zui61bP0c87LBDE+7shEjvdKbAL8NsvhL/ST3A+qXOpAa/xw1dstjpT1DfErcrRWygX+4RVzTp49NTmHkr7ykLDaabTY4imgPLUdhcHXr4aXJRGZUW4uCi7QS9s0Xs5qw38Eo4lH+G7+qs0TVb8tXDuGyQit8tf/k0Pz9DAwDLyCzKt4o9/tqua9zMdR8NiDuYgmV7ZdQRPLZlfDVI4HsMgOeRqT4lfbEsXxNyWwIUxirbeVjuc773gQkoseXM8a1pP45i37XG8sjEDttHGnxGSlPfuFGPJSggO6Q0DjfquruxYHB2QzCfXaAmPILw/ldnp6pCpa3egnphqx6SdJOl0jf6dsMlZ5HiCP5Wxq8JxTs6IKASt5SsX1oiZkHRr9pebCK4FNNpdsJdjGSioL5/bpi4u0VDaz4MWLVDdKGkLJTvH54uagKNR2ZHg54SEa24xEuHTMJFJHcLA");
		Get.setLastDay(-1);
		Get.setSiteCode(SiteCodeType.AUSTRALIA);
		Get.setApiContext();

		ExcelFileUtil excel = new ExcelFileUtil();
		List<EBayInfo> ebst = new ArrayList<EBayInfo>();
		String shiptimess;
		String shiptypess = null;
		String sku;
		String paid;

		if (Get.Get()) {
			OrderType[] allOrders = Get.getOrders();
			for (OrderType order : allOrders) {
				System.out.println("------------------------------------------------------------------");
				System.out.println("订单号:" + order.getOrderID());
				System.out.println("购买人ID:" + order.getBuyerUserID());
				System.out.println("订单状态:" + order.getOrderStatus().value());
				System.out.println("支付状态:" + order.getCheckoutStatus().getStatus().value());
				System.out.println("金额小记:" + order.getSubtotal().getValue());
				System.out.println("金额总计:" + order.getTotal().getValue());
				System.out.println("支付方式:" + order.getCheckoutStatus().getPaymentMethod().name());
				if (order.getShippedTime() == null) {
					System.out.println("发货状态：未发货");
					shiptimess = "未发货";
					shiptypess = "未发货";
				} else {
					System.out.println("发货时间:" + order.getShippedTime().getTime().toGMTString());
					shiptimess = order.getShippedTime().getTime().toGMTString();
					System.out.println("物流名称:" + order.getShippingServiceSelected().getShippingService());
					shiptypess = order.getShippingServiceSelected().getShippingService();
				}
				System.out.println("收件人:" + order.getShippingAddress().getName());
				System.out.println("收件地址:" + order.getShippingAddress().getStreet2()
						+ order.getShippingAddress().getStreet1() + " " + order.getShippingAddress().getStreet() + " "
						+ order.getShippingAddress().getCityName() + " "
						+ order.getShippingAddress().getStateOrProvince() + " "
						+ order.getShippingAddress().getCountryName());

				String shipaddresss = order.getShippingAddress().getStreet2() + order.getShippingAddress().getStreet1()
						+ " " + order.getShippingAddress().getStreet() + " " + order.getShippingAddress().getCityName()
						+ " " + order.getShippingAddress().getStateOrProvince() + " "
						+ order.getShippingAddress().getCountryName();

				System.out.println("邮编:" + order.getShippingAddress().getPostalCode());
				System.out.println("手机号:" + order.getShippingAddress().getPhone());
				System.out.println("订单创建时间：" + order.getCreatedTime().getTime().toGMTString());

				System.out.println("购买的商品:" + order.getTransactionArray().getTransactionLength());
				if (order.getTransactionArray().getTransactionLength() > 0) {
					System.out.println("-------|Products|------");
					for (TransactionType product : order.getTransactionArray().getTransaction()) {
						System.out.println("商品 ID:" + product.getTransactionID());
						System.out.println("商品名称 :" + product.getItem().getTitle());
						System.out.println("eBay Item id:" + product.getItem().getItemID());
						if (product.getVariation() == null) {
							System.out.println("SKU:" + product.getItem().getSKU());
							sku = product.getItem().getSKU();
						} else {
							System.out.println("SKU:" + product.getVariation());
							sku = product.getVariation() + "";
						}
						if (product.getAmountPaid() != null) {
							System.out.println("支付金额:" + product.getAmountPaid().getValue());
							paid = product.getAmountPaid().getValue() + "";
						} else {
							System.out.println("是否付款：未付款");
							paid = "未付款";
						}
						System.out.println("购买数量:" + product.getQuantityPurchased());

						EBayInfo eb = new EBayInfo(order.getOrderID(), order.getBuyerUserID(),
								order.getOrderStatus().value(), order.getCheckoutStatus().getStatus().value(),
								order.getSubtotal().getValue() + "", order.getTotal().getValue() + "",
								order.getCheckoutStatus().getPaymentMethod().name(), shiptimess, shiptypess,
								order.getShippingAddress().getName(), shipaddresss,
								order.getShippingAddress().getPostalCode(), order.getShippingAddress().getPhone(),
								order.getCreatedTime().getTime().toGMTString(), product.getTransactionID(),
								product.getItem().getTitle(), product.getItem().getItemID(), sku, paid,
								product.getQuantityPurchased() + "");

						ebst.add(eb);

					}
				}
			}
			

		} else {
			System.out.println("获取失败");
		}
	}
}
